import Router from '../function/route/routetest';
import mySqlConnection from '../function/mysql';
import { TransactionManager } from '../function/db/transactionmanager';
import { error, log } from 'console';

// 实例化路由对象
const router = new Router();

const config = {
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'testdatabase',
}

//实例化数据库对象
const mysqlHandler = new mySqlConnection(config, true)

// 注册路由和处理程序  
router.registerRoute('/testDB', 'GET', (req, res) => {
    mysqlHandler.executeQuery('select * from t_userinfo where name = ?', ['杨尚东'])
        .then(results => {
            res.writeHead(200, { 'Content-Type': 'Application/json' });
            res.end(JSON.stringify(results.rows));
        })
    mysqlHandler.closeConnection()
});

// 创建HTTP服务器  端口默认为3000
router.createServer()